/**
 * Description:
 * Class Name:FileInputStreamTest
 * Date:2022/5/1 16:44
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第15章_输入输出._15_3_字节流和字符流._15_3_1_InputStream和Reader;

import java.io.FileInputStream;
import java.io.IOException;

public class FileInputStreamTest {
    public static void main(String[] args) throws IOException {
        // 创建字节输入流
        String package_path = "./src/" + FileInputStreamTest.class.getName().replace(".", "/") + ".java";
//        var fis = new FileInputStream("./src/疯狂Java讲义/第15章_输入输出/_15_3_字节流和字符流/_15_3_1_InputStream和Reader/FileInputStreamTest.java");
        var fis = new FileInputStream(package_path);
        // 创建一个长度为1024的读取单位
        var byteBuffer = new byte[1024];
        var hasRead = 0;
        while ((hasRead = fis.read(byteBuffer)) > 0){
            System.out.println(new String(byteBuffer, 0, hasRead));
        }
        // 关闭文件输入流，放在finally中更安全
        fis.close();
    }
}
